package top.shiyiri.shops.controller;

import com.alibaba.fastjson.JSONObject;
import top.shiyiri.shops.bean.EraHotShopTop10;
import top.shiyiri.shops.service.EraHotShopTop10Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;


/**
 * @author Aunean
 * @date 2021/12/24
 */
@Controller
public class EraHotShopTop10Controller {

    @Autowired
    private EraHotShopTop10Service service;

    @RequestMapping("/eraHotShopTop10ByPage")
    @ResponseBody
    public String eraHotSHopTop10ByPage(int page, HttpSession session) {
//        System.out.println(page);
        List<EraHotShopTop10> list = service.eraHotSHopTop10ByPage(page, 5);

        int lines = service.totalLines();

        int pages = lines%5 == 0? lines/5: lines/5+1;

        session.setAttribute("pages", pages);
        session.setAttribute("page", page);

        return JSONObject.toJSONString(list);
    }

    @ResponseBody
    @RequestMapping("/getEraHotShopTop10Pages")
    public Integer getEraHotShopTop10Pages(HttpSession session) {

        int pages = (Integer) session.getAttribute("pages");

        return pages;
    }

    @ResponseBody
    @RequestMapping("/eraHotShopTop10")
    public String eraHotShopTop10() {

        List<EraHotShopTop10> list = service.eraHotShopTop10();

        return JSONObject.toJSONString(list);
    }

}
